//Erstellt von Moritz Liepe
package main;

import java.util.UUID;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;

public class ProgressControl extends Figure implements IModuleControl {

	private int x, y, width, height;
	private float percentage;
	private String type, address;
	private boolean connectable;
	private final XYLayout layout = new XYLayout();
	private UUID id;
	
	public ProgressControl(){
		id = UUID.randomUUID();
	}
	
	public UUID getID()
	{
		return this.id;
	}
	
	public void setID(String ID){
		this.id = UUID.fromString(ID);
	}
	
	@Override
	public String getType() {
		return type;
	}
	
	@Override
	public String getAddress() {
		return address;
	}

	@Override
	public boolean isConnectable() {
		return connectable;
	}

	@Override
	public int getX() {
		return x;
	}

	@Override
	public void setX(int x) {
		this.x = x;
	}

	@Override
	public int getY() {
		return y;
	}

	@Override
	public void setY(int y) {
		this.y = y;
	}

	@Override
	public int getWidth() {
		return width;
	}
	
	@Override
	public void setWidth(int width) {
		this.width = width;
	}
	
	@Override
	public int getHeight() 
	{
		return height;
	}
	
	@Override
	public void setHeight(int height) 
	{
		this.height = height;
	}

	@Override
	public void setType(String type) 
	{
		this.type = type;
	}

	@Override
	public void setAddress(String address) 
	{
		this.address = address;
	}

	@Override
	public void setConnectable(boolean connectable) 
	{
		this.connectable = connectable;
	}
	
	public float getProgress()
	{
		return this.percentage;
	}
	
	public void setProgress(float percentage){//Set Percentage as a value between 0 and 1
		
		this.percentage = percentage;
		float progressWidth = percentage/1.0F * width;
		((Figure)this.getChildren().get(0)).setSize((int)progressWidth, height);
	}

	@Override
	public void paint() {
		this.setLayoutManager(layout);	
		this.setOpaque(true);
		this.setBorder(new LineBorder(ColorConstants.black));
		this.setBackgroundColor(ColorConstants.white);
		Figure progress = new Figure();
		progress.setLayoutManager(new XYLayout());
		progress.setOpaque(true);
		progress.setBackgroundColor(ColorConstants.green);
		this.add(progress, new Rectangle(0,0,0,height));

	}

	@Override
	public String getValue() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setValue(String value) {
		// TODO Auto-generated method stub
		
	}

}
